<%@page import="db_interaction.Mensagens"%>
<%@page import="db_interaction.Amigos"%>
<%@page import="java.util.ArrayList"%>
<%@include file="header_general.jsp"%>

<div class="mainbar">


    <%
        String camiho_foto_user3 = new String();
        Amigos friend_request = new Amigos();
        Mensagens NewMessages = new Mensagens();
        Fotos res_foto = new Fotos();
        Fotos f3 = new Fotos();
        Utilizador user = new Utilizador();
        Utilizador user_update = new Utilizador();
        Notificacao noti2 = new Notificacao();
        List<Notificacao> list_notifications = null;
        List<Notificacao> list_notifications_friend_requests = new ArrayList();
        List<Notificacao> list_notifications_new_messages = new ArrayList();
        List<Notificacao> list_notifications_new_publications = new ArrayList();

        list_notifications = noti2.SelectAllNotifications((Integer) session.getAttribute("id_user"));

        for (int i = 0; i < list_notifications.size(); i++) {
            if (list_notifications.get(i).GETNotificacoes_amigos()) {
                list_notifications_friend_requests.add(list_notifications.get(i));
            }
            if (list_notifications.get(i).GETNotificacoes_mensagens()) {
                list_notifications_new_messages.add(list_notifications.get(i));
            }
            if (list_notifications.get(i).GETNotificacoes_publicacoes()) {
                list_notifications_new_publications.add(list_notifications.get(i));
            }
        }

        out.print("<h2><span>Friend Requests</span></h2>");
        for (int i = 0; i < list_notifications_friend_requests.size(); i++) {

            user = friend_request.SelectFriendRequest(list_notifications_friend_requests.get(i).GETNotificacoes_amigos_id());
            user_update = friend_request.SelectIdUserUpdate(list_notifications_friend_requests.get(i).GETNotificacoes_amigos_id());
            res_foto = f3.SelectFotoUser(user_update.getid());

            if (res_foto == null) {
                camiho_foto_user3 = "default_photo.jpg";
            } else {
                camiho_foto_user3 = res_foto.GETFotos_foto();
            }

            out.print("<div class='article'>");
            out.print("<img src='/TheHive/images/" + camiho_foto_user3 + "' style='float:left' width='40px'></img>");
            out.print("<h3><span>" + user_update.getNome() + "</span></h3>");


            // colocar form para aceiar o pedido de amizade

            out.print("<form method='post' id='AcceptFriendRequest' action='/TheHive/friends/ConfirmAddFriend.jsp'>");
            out.print("<span>");
            out.print("<input type='hidden' value='" + user_update.getid() + "' name='idUserFriendRequest' id='idUserFriendRequest'/>");
            out.print("<input type='hidden' value='" + user.getid() + "' name='idUserFriendRequestAmigo' id='idUserFriendRequestAmigo'/>");
            out.print("<input name='search' type='submit' value='Accept Request' id='AcceptRequest' style='margin-top: -40px; margin-left: 370px;' class='btn'/>");
            out.print("</span>");
            out.print("</form>");


            out.print("<form method='post' id='RejectFriendRequest' action='/TheHive/friends/RejectAddFriend.jsp'>");
            out.print("<span>");
            out.print("<input type='hidden' value='" + user_update.getid() + "' name='idUserFriendRequest' id='idUserFriendRequest'/>");
            out.print("<input type='hidden' value='" + user.getid() + "' name='idUserFriendRequestAmigo' id='idUserFriendRequestAmigo'/>");
            out.print("<input name='search' type='submit' value='Reject Request' id='AcceptRequest' style='margin-top: -55px; margin-left: 570px;' class='btn'/>");
            out.print("</span>");
            out.print("</form>");



            out.print("</div>");

            out.print("<hr>");
        }
        out.print("<br />");
        out.print("<br />");

        out.print("<h2><span>New Messages</span></h2>");
        for (int i = 0; i < list_notifications_new_messages.size(); i++) {

            user = NewMessages.SelectNewMessages(list_notifications_new_messages.get(i).GETNotificacoes_mensagens_id());
            user_update = NewMessages.SelectNewMessagesAmotherUser(list_notifications_new_messages.get(i).GETNotificacoes_mensagens_id());
            res_foto = f3.SelectFotoUser(user.getid());


            if (res_foto == null) {
                camiho_foto_user3 = "default_photo.jpg";
            } else {
                camiho_foto_user3 = res_foto.GETFotos_foto();
            }

            out.print("<div class='article'>");
            out.print("<img src='/TheHive/images/" + camiho_foto_user3 + "' style='float:left' width='40px'></img>");
            out.print("<h3><span>" + user.getNome() + "</span></h3>");


            // colocar form para aceiar o pedido de amizade

            out.print("<form method='post' id='AcceptFriendRequest' action='/TheHive/messages/SeeMessagesUserNotification.jsp'>");
            out.print("<span>");
            out.print("<input type='hidden' value='" + user.getid() + "' name='idusermessage' id='idusermessage'/>");
            out.print("<input type='hidden' value='" + user_update.getid() + "' name='idusermessageamigo' id='idUserFriendRequestAmigo'/>");
            out.print("<input name='search' type='submit' value='View Conversation' id='ViewConversation' style='margin-top: -40px; margin-left: 370px;' class='btn'/>");
            out.print("</span>");
            out.print("</form>");

            out.print("</div>");

            out.print("<hr>");
        }
        out.print("<br />");
        out.print("<br />");


        /**
         * ************** IMPLEMENTAR ESTA AQUI NOTIFICACOES DE NOVAS
         * PUBLICACOES DE AMIGOS ****************
         */
        /*out.print("<h2><span>New Publications</span></h2>");
         for (int i = 0; i < list_notifications_new_publications.size(); i++) {



         out.print("<div class='article'>");
         //out.print("<img src='/TheHive/images/' style='float:left' width='90px'></img>");
         out.print("<h3><span></span></h3>");
         out.print("<p></p>");
         out.print("</div>");
         }
         out.print("<br />");
         out.print("<br />");*/

    %>

</div>


<%@include file="sidebar_general.jsp"%>